﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows;
using UBCon.Ribbon.Interfaces;

namespace UBCon.Ribbon.Models
{
    public class QAToolBarItemModel:INotifyPropertyChanged
    {
        #region Private propeties

        private string text;
        private UIElement uiElement;
        private bool isVisible = true, isEnabled = false, isValid=true;

        #endregion

        #region Public properties

        /// <summary>
        /// Gets or sets boolean value which indicates this control is visible in items.
        /// </summary>
        public bool IsValid 
        {
            get 
            {
                return isValid;
            }
            set 
            {
                isValid = value;
                OnPropertyChanged("IsValid");
            }
        }

        /// <summary>
        /// Gets or sets boolean value which indicates this control is enabled or not.
        /// </summary>
        public bool IsEnabled 
        {
            get 
            {
                return isEnabled;
            }
            private set
            {
                isEnabled = value;
                OnPropertyChanged("IsEnabled");
            }
        }
        /// <summary>
        /// Gets or sets item's text.
        /// </summary>
        public string Text 
        {
            get 
            {
                return text;
            }
            set
            {
                text = value;
                OnPropertyChanged("Text");
            }
        }

        /// <summary>
        /// Gets or sets associated UI control.
        /// </summary>
        public UIElement UIElement 
        {
            get 
            {
                return uiElement;
            }
            set 
            {
                uiElement = value;
                if (value != null)
                {
                    IsEnabled = true;
                }
                else 
                {
                    IsEnabled = false;
                }
            }
        }

        /// <summary>
        /// Gets or sets a boolean value which indicates whether this control is visible or not.
        /// </summary>
        public bool IsVisible 
        {
            get 
            {
                return isVisible;
            }
            set 
            {
                isVisible = value;
                OnPropertyChanged("IsVisible");
                if (UIElement != null)
                {
                    if (isVisible)
                    {

                        UIElement.SetValue(FrameworkElement.VisibilityProperty, Visibility.Visible);
                    }
                    else
                    {
                        UIElement.SetValue(FrameworkElement.VisibilityProperty, Visibility.Collapsed);
                    }
                }
            }
        }
        #endregion

        #region INotifyPropertyChanged implementation

        public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChanged(string propertyName) 
        {
            if (PropertyChanged != null) 
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        #endregion
    }
}
